<template>
    <div class="Welcome">
        <el-table
                :data="list"
                height="250"
                border
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="ID"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="商品名称">
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
  import axios from 'axios'

  export default {
    data() {
      return {
        list: []
      }
    },
    mounted() {
      console.log("mounted");
      let _self = this;
      const instance = axios.create({
        baseURL: 'http://localhost:9527'
      });

// Alter defaults after instance has been created
      instance.defaults.headers.common['Authorization'] = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImNyZWF0ZWQiOjE2MDYzODk4MDg1MzEsImV4cCI6MTYwNjk5NDYwOH0.NhuYU6bXM7glemvMvJEYJyh9JkPL9iB0eXZhnnSFc1e-zW-1m1EYSlwLevz71rNITpf3tarnO4LU34ST_7Cw5w";
      instance.get("/product/list")
        .then(function ({data: result}) {
          console.log(result);
          // let data = response.data;
          let code = result.code;
          console.log(typeof code);
          if (code === 200) {
            _self.list = result.data.list;
          } else {
            let msg = result.message;
            console.log(msg);
          }
        });
    }
  };
</script>
